package com.bosssoft.service_order.controller;

import com.bosssoft.base.entity.Result;
import com.bosssoft.base.enums.ResultCodeEnum;
import com.bosssoft.service_order.domain.dto.CartDTO;
import com.bosssoft.service_order.domain.po.Cart;
import com.bosssoft.service_order.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("cart")
@Api(value = "结算")
public class CartController {

    @Autowired
    private CartService cartService;

    @ApiOperation(value = "添加结算商品")
    @PostMapping("add")
    public Result addCart(@RequestBody CartDTO cartDTO) {
        if (cartService.add(cartDTO)) {
            return Result.build(ResultCodeEnum.SUCCESS.getCode(), "添加成功", null);
        }
        return Result.build(ResultCodeEnum.ERROR.getCode(), "添加失败", null);
    }

    @ApiOperation(value = "删除结算商品")
    @PostMapping("delete")
    public Result deleteCart(CartDTO cartDTO) {
        if (cartService.delete(cartDTO)) {
            return Result.build(ResultCodeEnum.SUCCESS.getCode(), "删除成功", null);
        }
        return Result.build(ResultCodeEnum.ERROR.getCode(), "删除失败", null);
    }

    @ApiOperation(value = "查询结算商品")
    @PostMapping("query")
    public Result queryCart(CartDTO cartDTO){
        Cart cart = cartService.query(cartDTO);
        return Result.build(ResultCodeEnum.SUCCESS.getCode(), "查询成功", cart);
    }
}
